app.controller("brandController",function ($controller,$scope,brandService) {
    //伪继承
    $controller("baseController",{$scope:$scope});
    //查询所有品牌
    $scope.findAll=()=>{
       brandService.findAll().success(resp=>{
            $scope.list = resp;
        })
    }
    //根据关键字搜索品牌
    $scope.search=()=>{
        //参数1：代表要查询的条件 参数2：代表当前页 参数3：代表每页大小
        brandService.search($scope.searchEntity,$scope.paginationConf.currentPage,$scope.paginationConf.itemsPerPage).success(resp=>{
            //更新当前记录集合
            $scope.list = resp.rows;
            //更新总记录数
            $scope.paginationConf.totalItems=resp.total;
        })
    }

    //保存品牌
    $scope.save=()=>{
        let url = "../brand/add.do";    //添加
        if($scope.entity.id){           //如果有id存在，就是修改操作
            url = "../brand/update.do"; //修改
        }
        //提交修改
        brandService.save(url,$scope.entity).success(resp=>{
            if(resp.success){
                $scope.search();    //刷新页面
            }else{
                alert(resp.message);
            }
        })
    }
    //修改品牌界面
    $scope.updateUI=(brand)=>{
        $scope.entity = brand;
    }

    //删除品牌
    $scope.del=()=>{
        brandService.del($scope.selectIds).success(resp=>{
            if(resp.success){
                $scope.search();    //刷新页面
            }else{
                alert(resp.message);
            }
        })
    }
})